package MOLE.App;

import java.util.*;
import MOLE.*;

public class Account extends Every
{
	public int Uid = 0; //�ʻ�������
	public String AccountOwnerName = "";
	 public double Balance = 0; //���
	public java.math.BigDecimal TotalPay = new java.math.BigDecimal(0);
	public boolean IsInFreez = false;




	public Account(int userid)
	{
		//
		// TODO: �ڴ˴���ӹ��캯���߼�
		//
		Uid = userid;
		 Balance = GetBalance(userid);
	}
	public Account() //kkong account ,kaihu yong
	{

	}


	/** 
	 new account --Kaihu
	 
	 @param uid
	 @return 
	*/
	public final Account _NewAccount(int uid)
	{

		Balance = 0;
		Uid = uid;
		 return this;

	}



	public static DataTable Search(int uid)
	{
		String s = "exec Account_List  " + String.valueOf(uid);
		return MOLE.SQL.GetDataTable(s);
		//CREATE PROC   SearchAccount
		//    @userid   int=0      --yonhur minzi  
		//
		//AS
		//
		//
		//BEGIN
		//    DECLARE @sqlText  varchar(1000)
		//  	if(@userid=0)
		// 	
		// 		  SET @sqlText =' select * from bank    order by hy_num desc'
		//	else
		//		 
		// 		 SET @sqlText =' select * from bank  where hy_num='+cast(@userid as varchar  )+'  order by hy_num desc'
		//   
		// --EXEC (@sqlText)
		//print(@sqltext)
		//END
		//GO


	}
	/** 
	 lock the account
	 
	 @return 
	*/
	public final ArrayList FreezTrans()
	{
		SQLOS o = new SQLOS("bank");
		o.RS("Zt", "t");
		Hashtable h = o.UpdateTrans("hy_num", Uid);

		ArrayList a = new ArrayList();
		a.add(h);
		 return a;
	}

	public final boolean Freez()
	{
		try
		{
			ArrayList a = FreezTrans();
			MOLE.SQL.ExecuteSqlTranByArraylist(a);
			return true;
		}
		catch (RuntimeException ee)
		{
			this.StausMsg = ee.toString();
			return false;
		}
	}
	public final ArrayList FreezClearTrans()
	{
		SQLOS o = new SQLOS("bank");
		o.RS("Zt", "q");
		Hashtable h = o.UpdateTrans("hy_num", Uid);

		ArrayList a = new ArrayList();
		a.add(h);
		return a;
	}

	public final boolean FreezClear()
	{
		try
		{
			ArrayList a = FreezClearTrans();
			MOLE.SQL.ExecuteSqlTranByArraylist(a);
			return true;
		}
		catch (RuntimeException ee)
		{
			this.StausMsg = ee.toString();
			return false;
		}
	}

	public final boolean IsFreez()
	{
		return false;
	}




	/** 
	 get balance
	 
	 @param uid
	 @return 
	*/
	public static double GetBalance(int uid)
	{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
			///#region
		double balance = 0;
		String sql = "select * from bank where hy_num=" + String.valueOf(uid);
		DataTable d = MOLE.SQL.GetDataTable(sql);
		if (d.Rows.size() != 0)
		{
			balance = MOLE.str.ConvertToDouble(d.Rows[0]["balance"]);
		}

		return balance;
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
			///#endregion

	}


	/** 
	 
	 
	 @param momey
	 @return 
	*/
	public final boolean IsMoneyOver(double momey)
	{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
			///#region

		if (Balance < momey)
		{
			return true;
		}
		else
		{
			return false;
		}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
			 ///#endregion

	}





	/** 
	 charge pu
	 
	 @param money
	 @param demo
	 @return 
	*/
	public final ArrayList _Charge(double money, String demo)
	{
		 ArrayList a = new ArrayList();
		 ArrayList charge = ChargeOnly(money);
		ArrayList log = Log(1, money, demo);

		a = MOLE.comm.HabinArraylist(charge, log);
		return a;
	}

	 public final ArrayList ChargeOnly(double money)
	 {

		String upsql = "  UPDATE   bank   set Balance=Balance+" + String.valueOf(money) + "" + " where  hy_num=" + String.valueOf(Uid);
		Hashtable h = new Hashtable();
		h.put(upsql,null);

		 ArrayList a = new ArrayList();
		a.add(h);

		return a;

	 }


	/** 
	  ֧��
	 
	 @param money
	 @param demoOfPay
	 @return 
	*/
	 public final ArrayList _Pay(double money, String demoOfPay)
	 {
		ArrayList a = new ArrayList();

		if (IsFreez())
		{
			this.StausCode = 1;
			this.StausMsg = AccountResx.FreezStatuTips;
		}
		else
		{
			ArrayList h1 = PayOnly(money);
			ArrayList h2 = (Log(2, money, demoOfPay));


			a = MOLE.comm.HabinArraylist(h1, h2);
		}
		return a;
	 }

	 public final ArrayList PayOnly(double money)
	 {

		Hashtable h = new Hashtable();


		String upsql = "  UPDATE   bank   set Balance=Balance-" + String.valueOf(money) + "," + "output_money=output_money-" + String.valueOf(money) + " where  hy_num=" + String.valueOf(Uid);

		h.put(upsql,null);



		ArrayList a = new ArrayList();
		a.add(h);

		 return a;
	 }





	 /** 
	 Detaio log 
	 
	 @param type
	 @param money
	 @param demo
	 @return 
	 */
	public final ArrayList Log(int type, double money, String demo)
	{
		//AccountDetail  o=new AccountDetail();
		ArrayList h = new ArrayList();
		 if (type == 1) //charge
		 {
			MOLE.SQLOS o = new MOLE.SQLOS("bank_log");
			o.RS("balance", money);
			o.RS("bz", demo);
			o.RS("Addtime", java.time.LocalDateTime.now().toString());
			o.RS("hy_num", Uid);
			h = o.InserTrans();
		 }
		else //PAY
		{
			MOLE.SQLOS o = new MOLE.SQLOS("bank_log");
			o.RS("balance", 0 - money);
			o.RS("bz", demo);
			o.RS("Addtime", java.time.LocalDateTime.now().toString());
			o.RS("hy_num", Uid);
			h = o.InserTrans();
		}

		 return h;
	}

//		public 

	public final boolean getIsHasAccInfo()
	{
		 String sql = "select* from  Bank  where hy_num=" + String.valueOf(Uid);
		DataTable d = MOLE.SQL.GetDataTable(sql);
		if (d.Rows[0]["zhufumima"].toString().equals(""))
		{
			return false;
		}
		else
		{
			return true;
		}
	}

}